#!/sbin/openrc-run

name="LDAP load-balancer"
description="Stand-alone LDAP load balancer daemon"
description_checkconfig="Check configuration file (errors are logged to syslog)"

extra_commands="checkconfig"

: ${cfgfile:="/etc/openldap/lloadd.conf"}
: ${start_wait=50}  # milliseconds

command=/usr/sbin/lloadd
command_args="
	-u ldap -g ldap
	-l DAEMON
	${listen_uris:+-h \"$listen_uris\"}
	-d 0
	-f $cfgfile
	${command_args:-}
	"
command_background=yes

pidfile="/run/$RC_SVCNAME.pid"
start_stop_daemon_args="
	${start_wait:+--wait $start_wait}
	${start_stop_daemon_args:-}
	"
# See https://github.com/OpenRC/openrc/pull/558
supervise_daemon_args=" $supervise_daemon_args"

required_files="$cfgfile"

depend() {
	need net
	after firewall
	before dbus hald avahi-daemon
	provide ldap
}

start_pre() {
	$command $command_args -t >/dev/null 2>&1 || $command $command_args -t
}

checkconfig() {
	ebegin "Checking $name configuration"
	$command $command_args -t
	eend $?
}
